using UnityEngine;

namespace UI.BankingPanel
{
    /// <summary>
    /// 坐庄收款系统主管理类
    /// 挂载到M_Panel节点上，负责初始化BankingCtrl和数据持久化管理器
    /// </summary>
    public class BankingPanelMgr : MonoBehaviour
    {
        #region 组件引用
        [Header("控制器")]
        [SerializeField] private BankingCtrl controller;
        
        [Header("数据管理器")]
        [SerializeField] private BankingDataManager dataManager;
        #endregion

        #region Unity生命周期
        private void Awake()
        {
            InitializeDataManager();
            InitializeController();
        }
        #endregion

        #region 初始化
        /// <summary>
        /// 初始化数据管理器
        /// </summary>
        private void InitializeDataManager()
        {
            // 如果场景中没有BankingDataManager，创建一个
            if (BankingDataManager.Instance == null)
            {
                GameObject dataManagerObj = new GameObject("BankingDataManager");
                dataManager = dataManagerObj.AddComponent<BankingDataManager>();
                DontDestroyOnLoad(dataManagerObj);
            }
            else
            {
                dataManager = BankingDataManager.Instance;
            }
        }
        
        /// <summary>
        /// 初始化控制器
        /// </summary>
        private void InitializeController()
        {
            if (controller == null)
            {
                controller = GetComponent<BankingCtrl>();
                if (controller == null)
                {
                    controller = gameObject.AddComponent<BankingCtrl>();
                }
            }
            
            controller.Initialize();
        }
        #endregion
    }
} 